// credits/components/apply-technology-integral/index.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      default: false
    },
    storeId: {
      type: String,
      default: ''
    },
    detailData: {
      type: Object,
      default: null,

    }
  },
  observers: {
    detailData(val) {
      let formData = {
        desc: '',
        images: []
      }

      if (val) {
        formData.desc = val.desc
        formData.images = val.file_ids ? val.file_ids.split(',').map(url => {
          return {
            url
          }
        }) : []
      }

      this.setData({
        formData
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    formData: {
      desc: '111',
      images: []
    },
    test:'333'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChangeImages(event) {
      this.setData({
        'formData.images': event.detail
      })
    },
    inputChange(event) {
        this.setData({
            'formData.desc': event.detail
          })
    },
    onCancel() {
      this.triggerEvent('close')
    },
    onConfirm() {
      console.log(this.data.test)
      wx.ajax.post('addScoreApply.action', {
        note: this.data.formData.desc,
        file_ids: this.data.formData.images.map(item => item.url).join(','),
        storeId: this.data.storeId,
      }).then(() => {
        wx.showToast({
          title: '申请成功',
          icon: 'success'
        })
        this.triggerEvent('refresh')
        this.onCancel()
      })
    }
  }
})